package controller

import (
	"poker/comm"
	"poker/pb/proto/common"
	"poker/pb/proto/match"
	"poker/ws"

	"github.com/gogo/protobuf/proto"
	"github.com/smallnest/rpcx/log"
)

func MatchList(r *ws.Request) {
	req := &match.MatchListReq{}
	res := &match.MatchListRes{}

	defer func() {
		if err := r.Send(res); err != nil {
			log.Errorf("login response failed, err: %v", err)
		}
	}()

	if err := proto.Unmarshal(r.ByteData, req); err != nil {
		log.Errorf("invalid match list message, err: %v", err)
		res.Code = common.Code_Abnormal
		return
	}

	matchs := []*match.Match{}
	// var resMatchs = make([]*match.Match, 0)
	// var myMatch *match.MyMatch
	// for _, v := range matchs {
	// 	if v.IsMatchRun() && int32(v.GetMatchConf().ClassType) == req.ClassType && (channelId == v.GetMatchConf().ChannelId || v.GetMatchConf().ChannelId == 0) {
	// 		cost := make([]*common.Item, 0)
	// 		for _, item := range v.GetMatchConf().CostItems {
	// 			cost = append(cost, &common.Item{
	// 				Id:    item.ID,
	// 				Count: item.Count,
	// 			})
	// 		}

	// 		matchUser := v.GetPlayer(r.GetConn().ID)
	// 		if matchUser != nil {
	// 			myMatch = new(match.MyMatch)
	// 			myMatch.IsDieOut = matchUser.DieOut != 0
	// 		}

	// 		resMatchs = append(resMatchs, &match.Match{
	// 			MatchInsID: v.ID,
	// 			MatchId:    v.GetMatchConf().MatchId,
	// 			Name:       v.GetMatchConf().Name,
	// 			Title:      v.GetMatchConf().Title,
	// 			Icon:       v.GetMatchConf().Icon,
	// 			ClassType:  int32(v.GetMatchConf().ClassType),
	// 			EventType:  int32(v.GetMatchConf().EventType),
	// 			MinVipLv:   int32(v.GetMatchConf().MinVipLv),
	// 			// LoopType:          pb.LoopType(v.GetMatchConf().LoopType),
	// 			// OpenType:          pb.OpenType(v.GetMatchConf().OpenType),
	// 			StartTime:         v.GetOpenTime(),
	// 			Round:             int32(v.GetMatchConf().MatchRound),
	// 			CurRound:          int32(v.GetRound()),
	// 			IsFinal:           v.IsFinalRound(),
	// 			TotalNum:          int32(v.GetMatchConf().OpenNum),
	// 			CurrentNum:        int32(v.CountPlayer()),
	// 			State:             v.GetMatchState(),
	// 			Cost:              cost,
	// 			Self:              myMatch,
	// 			CanRelive:         int32(v.GetMatchConf().CanRelive),
	// 			Position:          &match.Position{},
	// 			SignUpRestriction: v.GetMatchConf().SignUpRestriction,
	// 		})
	// 	}
	// }

	res.Matchs = matchs
	res.Joined = nil
	res.Timestamp = comm.GetNowSecond()
}
